import { defineStore } from 'pinia'
import { getConsultation } from '../api/Consultation'
import { getpingData } from '../api/Consultation'
import { gethistoryDta } from '../api/Consultation'
import { getgridData } from '../api/Consultation'
import { getgridliData } from '../api/Consultation'
import { historyDta } from '../api/Consultation'

export const usecurrentStore = defineStore('user', {
  state: () => ({
    getdocterResuly: [],
    pingListResults: [],
    endresults: [],
    historyResult: [],
    gridResults: [],
    gogridResults: [],
    gopiongResults: [],
    userId: JSON.parse(localStorage.getItem('userId') || '0'),
    sessionId: JSON.parse(localStorage.getItem('sessionId') || '0')
  }),
  actions: {
    // 查询问诊
    async handdocterData(userId: number, sessionId: string) {
      try {
        const Docsearch_List = await getConsultation(userId, sessionId)
        // console.log(Docsearch_List, 'Docsearch_List')

        this.$state.getdocterResuly = Docsearch_List.data.result

        // console.log('当前问诊', this.$state.getdocterResuly)
      } catch (error) {
        console.log('查询当前问诊失败', error)
      }
    },
    //查看历史问诊
    async historyData(userId: number, sessionId: string, page: number, count: number) {
      try {
        const history_List = await gethistoryDta(userId, sessionId, { page, count })
        console.log(history_List, '历史问诊')

        this.$state.historyResult = history_List.data.result

        console.log('历史问诊', this.$state.historyResult)
      } catch (error) {
        console.log('查询历史问诊失败', error)
      }
    },
    // 评论问诊
    async handPingdata(
      userId: number,
      sessionId: string,
      inquiryRecordId: number,
      doctorId: number,
      evaluate: string,
      majorDegree: number,
      satisfactionDegree: number
    ) {
      try {
        const ping_List = await getpingData(userId, sessionId, {
          inquiryRecordId,
          doctorId,
          evaluate,
          majorDegree,
          satisfactionDegree
        })
        console.log('评论问诊服务', ping_List)
        this.$state.pingListResults = ping_List.data
        console.log('评论问诊', this.$state.pingListResults)
      } catch (error) {
        console.log('评论失败', error)
      }
    },
    //获取礼物
    async gridData() {
      try {
        const Grid_list = await getgridData()
        console.log(Grid_list, '礼物')
        this.$state.gridResults = Grid_list.data.result
        console.log(this.$state.gridResults, '礼物查询')
      } catch (error) {
        console.log('礼物查询失败', error)
      }
    },
    //送礼物
    async gogridData(userId: number, sessionId: string, inquiryRecordId: number, giftId: number) {
      try {
        const goGrid_list = await getgridliData(userId, sessionId, { inquiryRecordId, giftId })
        console.log(goGrid_list, '礼物')
        this.$state.gogridResults = goGrid_list.data.result
        // console.log(this.$state.gogridResults, '送礼物')
      } catch (error) {
        console.log('礼物失败', error)
      }
    },
    async aagogridData(userId: number, sessionId: string, recordId: number) {
      try {
        const data = { recordId: recordId }
        const pingGrid_list = await historyDta(userId, sessionId, data)
        console.log(pingGrid_list, '历史评价')
        this.$state.gopiongResults = pingGrid_list.data.result
        console.log(this.$state.gopiongResults, '历史评价11')
      } catch (error) {
        console.log('历史评价错误', error)
      }
    }
  }
})
